/*
 * This file is part of GuitarMaster.
 * 
 * GuitarMaster is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * GuitarMaster is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.paris5.master2.guitarmaster.entity;

import com.paris5.master2.guitarmaster.bean.EcomProductType;
import java.io.Serializable;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Leticia Mahamed, Alice Khammy, mourad nedjahi, Saliou Mamadou Barry
 */
@Entity
@Table(name = "product_type")
public class ProductType implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id_product_type", nullable = false)
    private Integer idProductType;
    
    @Size(max = 100)
    @Column(name = "title", length = 100)
    private String title;
    
    @Lob
    @Size(max = 65535)
    @Column(name = "description", length = 65535)
    private String description;
    
    @Column(name = "price")
    private Float price;
    
    @JoinColumn(name = "id_score", referencedColumnName = "id_score")
    @ManyToOne(cascade = CascadeType.ALL)
    private Score score;
    
    @Lob
    @Column(name = "photo")
    private String photo;

    @Column(name="quantity")
    private Integer quantity;

    @JoinColumn(name = "id_category", referencedColumnName = "id_category")
    @ManyToOne
    private Category idCategory;

    public ProductType() {
    }
    
    public ProductType(EcomProductType pt){
        idProductType = pt.getIdProductType() ;
        title = pt.getTitle();
        description = pt.getDescription();
        price = pt.getPrice();
        score = new Score(pt.getScore());
        photo = pt.getPhoto();
        quantity=pt.getQuantity();
        idCategory = new Category(pt.getCategory());
    }

    public EcomProductType getEcomProductType(){
        EcomProductType pt = new EcomProductType();
        pt.setIdProductType(idProductType);
        pt.setTitle(title);
        pt.setDescription(description);
        pt.setPrice(price);
        pt.setScore(score.getEcomScore());
        pt.setPhoto(photo);
        pt.setQuantity(quantity);
        pt.setCategory(idCategory.getEcomCategory());
        return pt;
    }
    
    public ProductType(Integer idProductType) {
        this.idProductType = idProductType;
    }

    public Integer getIdProductType() {
        return idProductType;
    }

    public void setIdProductType(Integer idProductType) {
        this.idProductType = idProductType;
    }

    public String getTitle() {
        return title;
    }

    public Integer getQuantity() {
        return quantity;
    }

    public void setQuantity(Integer quantity) {
        this.quantity = quantity;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Float getPrice() {
        return price;
    }

    public void setPrice(Float price) {
        this.price = price;
    }

    public Score getScore() {
        return score;
    }

    public void setScore(Score score) {
        this.score = score;
    }

    public String getPhoto() {
        return photo;
    }

    public void setPhoto(String photo) {
        this.photo = photo;
    }

    public Category getIdCategory() {
        return idCategory;
    }

    public void setIdCategory(Category idCategory) {
        this.idCategory = idCategory;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idProductType != null ? idProductType.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ProductType)) {
            return false;
        }
        ProductType other = (ProductType) object;
        if ((this.idProductType == null && other.idProductType != null) || (this.idProductType != null && !this.idProductType.equals(other.idProductType))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "ProductType{" + "idProductType=" + idProductType + ", title=" + title + ", description=" + description + ", price=" + price + ", score=" + score + ", photo=" + photo + ", idCategory=" + idCategory + '}';
    }
}
